<template>
  <div class="detail">
    <van-tabs scrollspy sticky>
      <van-tab :title="'商品 '">
        <div class="detail-banner">
          <van-swipe
          
            @change="onChange"
            class="my-swipe"
            autoplay="3000"
            :loop="true"
            :show-indicators="false"
          >
            <van-swipe-item
              v-for="(item, index) in storeInfo.slider_image"
              :key="index"
            >
              <van-image class="auto-img" :src="item" />
            </van-swipe-item>
            <template #indicator>
              <div class="custom-indicator">{{ current + 1 }}/4</div>
            </template>
          </van-swipe>

          <div class="detail-content">
            <div class="detail-price-box">
              <div class="daily-price">￥{{ storeInfo.price }}</div>
              <div class="vip-price">￥{{ storeInfo.vip_price }}</div>
              <div class="vip-icon">
                <img
                  src=""
                />
              </div>
            </div>

            <div class="detail-title">
              {{ storeInfo.store_name }}
            </div>

            <div class="detail-more">
              <div class="more-1">原价:￥{{ storeInfo.ot_price }}</div>
              <div class="more-2">
                库存:{{ storeInfo.stock }}{{ storeInfo.unit_name }}
              </div>
              <div class="more-3">
                销量:{{ storeInfo.fsales }}{{ storeInfo.unit_name }}
              </div>
            </div>
          </div>
        </div>
      </van-tab>
      <van-tab :title="'评价 '">
        <div class="comment-box">
          <div class="user-comment">用户评价</div>
          <div class="user-more">
            <div class="comment-num">0%</div>
            好评率
          </div>
        </div>
      </van-tab>

      <van-tab :title="'推荐'">
        <div class="recommend-box">
          <div class="recommend-title">优品推荐</div>
          <van-swipe class="my-swipe" :autoplay="5000" indicator-color="white">
            <van-swipe-item
              class="swpie-item"
              v-for="(item, index) in swipe"
              :key="index"
            >
              <div
                class="swiper-box"
                v-for="items in item"
                :key="items.id"
                 @click='jump(items.id)'
              >
                <div class="swiper">
                  <div class="swiper-img">
                    <van-image class="auto-img" :src="items.image" />
                  </div>
                  <div class="swiper-name">{{ items.store_name }}</div>
                  <div class="swiper-price">￥{{ items.price }}</div>
                </div>
              </div>
            </van-swipe-item>
          </van-swipe>
        </div>
      </van-tab>
      <van-tab :title="'详情'">
        <div class="details">产品介绍</div>
        <div v-html="description"></div>
      </van-tab>
    </van-tabs>

    <div>
      <!-- s -->
      <Good :productId="id" :swipr="storeInfo"></Good>
    </div>
  </div>
</template>

<script>
import Good from "@/components/good";
export default {
  props: {
    id: String,
  },
  data() {
    return {
      // 轮播图
      storeInfo: [],
      // 轮播图显示的页码
      current: 0,

      // 推荐商品轮播图
      swipe: {
        a: [],
        b: [],
        c: [],
      },

      // 产品介绍
      description: [],
    };
  },
  methods: {
    onChange(index) {
      this.current = index;
    },
    jump(id){
        this.$router.push(`/detail/${id}`);
       this.$router.go(0);
    }
  },
  components: {
    Good,
  },
  created() {
    this.axios(`api/product/detail/${this.id}`).then((res) => {
      // console.log(res);
      this.storeInfo = res.data.data.storeInfo;
      this.swipe.a = res.data.data.good_list.slice(0, 6);
      this.swipe.b = res.data.data.good_list.slice(6, 12);
      this.swipe.c = res.data.data.good_list.slice(12, 18);
      this.description = res.data.data.storeInfo.description;
      // console.log(this.swipe);
    });
  },
};
</script>

<style lang="less" scoped>
.custom-indicator {
  position: absolute;
  right: 5px;
  bottom: 5px;
  padding: 2px 5px;
  font-size: 12px;
  background: rgba(0, 0, 0, 0.1);
}
.detail {
  background-color: rgb(245, 245, 245);
}
.detail-banner {
  .auto-img {
    width: 100%;
    height: 375px;
  }
}
.detail-content {
  background-color: #fff;
  padding: 10px 10px;
  .detail-price-box {
    display: flex;
    align-items: flex-end;
    .daily-price {
      font-size: 20px;
      font-weight: 700;
      color: red;
    }
    .vip-price {
      margin-left: 10px;
      font-size: 14px;
    }
    .vip-icon {
      width: 23px;
      height: 10.5px;
      margin-left: 5px;
      margin-top: -3px;

      img {
        width: 100%;
        height: 100%;
        display: block;
      }
    }
  }
  .detail-title {
    font-size: 15px;
    font-weight: 700;
    padding-top: 10px;
  }
  .detail-more {
    padding-top: 10px;
    display: flex;
    color: #999;
    font-size: 10px;
    .more-2 {
      margin: 0 auto;
    }
    .more-3 {
      margin-left: auto;
    }
  }
}

.comment-box {
  background-color: #fff;
  display: flex;
  align-items: center;
  padding: 5px;
  margin-top: 10px;

  .user-more {
    display: flex;
    align-items: center;
    font-size: 11px;
    color: #999;
    margin-left: auto;
    .comment-num {
      margin-left: auto;
      color: red;
    }
  }
}

.recommend-box {
  background-color: #fff;
  margin-top: 10px;
  .my-swipe {
    display: flex;
    .swpie-item {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;
      .swiper-box {
        width: 30%;
        display: flex;
        .auto-img {
          // border-radius: 5px;
          width: 100%;
          height: 107px;
        }
      }
    }
  }
}
.recommend-title {
  text-align: center;
  padding: 15px;
  color: #f57a37;
}
.swiper {
  width: 100%;
  // .swiper-img{
  //   border-radius: 5px;
  //   overflow: hidden;
  // }
  .swiper-name {
    text-align: left;
    width: 100%;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
    font-size: 14px;
  }
  .swiper-price {
    color: #fc4141;
    font-size: 14px;
  }
}

.details {
  background-color: #fff;
  text-align: center;
  margin-top: 10px;
  padding: 10px;
}
</style>